﻿using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace YunShop_WebAPI.BLL
{
    public class WxService
    {
        /// <summary>
        /// 根据code获取openId和session_key
        /// </summary>
        /// <param name="code"></param>
        /// <returns></returns>
        public static JObject GetOpenIdByCode(string code, string appid, string secret)
        {
            WeChatData data = new WeChatData();
            data.SetValue("appid", appid);
            data.SetValue("secret", secret);
            data.SetValue("js_code", code);
            data.SetValue("grant_type", "authorization_code");
            string url = "https://api.weixin.qq.com/sns/jscode2session?" + data.ToUrl();
            string result = HttpService.Get(url);
            //(new MemberService(MiniProgramType.MemberShop)).writeServiceLog("WeChatShop.OnLogin_GetOpenIdByCode", result, "1", "1");
            JObject jo = JObject.Parse(result);
            return jo;
        }
    }
}
